package com.tanhua.management.controller;

import cn.hutool.core.util.ObjectUtil;
import com.tanhua.management.service.DataDisplayService;
import com.tanhua.management.vo.DataDispalyVo;
import com.tanhua.management.vo.PageResultUsers;
import com.tanhua.management.vo.PageResultbution;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("dashboard")
@RestController
@Slf4j
public class DataDisplayController {

    @Autowired
    private DataDisplayService dataDisplayService;

    @GetMapping("summary")
    public ResponseEntity<DataDispalyVo> queryUserData(){
        try {
            DataDispalyVo dataDispalyVo = dataDisplayService.queryDataDispaly();
            if (ObjectUtil.isNotEmpty(dataDispalyVo)) {
                return ResponseEntity.ok(dataDispalyVo);
            }
        } catch (Exception e) {
            log.error("查询失败", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    @GetMapping("users")
    public ResponseEntity<PageResultUsers> queryUsers(@RequestParam String sd,@RequestParam String ed, @RequestParam Integer type){
        try {
            PageResultUsers pageResultUsers = dataDisplayService.queryUsers(sd,ed,type);
            if (ObjectUtil.isNotEmpty(pageResultUsers)) {
                return ResponseEntity.ok(pageResultUsers);
            }
        } catch (Exception e) {
            log.error("查询失败", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    @GetMapping("distribution")
    public ResponseEntity<PageResultbution> queryDistribution(@RequestParam String sd,@RequestParam String ed){
        try {
            PageResultbution pageResultbution = dataDisplayService.queryDistribution(sd,ed);
            if (ObjectUtil.isNotEmpty(pageResultbution)) {
                return ResponseEntity.ok(pageResultbution);
            }
        } catch (Exception e) {
            log.error("查询失败", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
